using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class UIManager : MonoBehaviour
{
	[Header("Stats")]
	[SerializeField] private PlayerStats stats;

	[Header("Bars")]
	[SerializeField] private Image healthBar;
	[SerializeField] private Image manaBar;
	[SerializeField] private Image expBar;

	[Header("Text")]
	[SerializeField] private TextMeshProUGUI levelTMP;
	[SerializeField] private TextMeshProUGUI healthTMP;
	[SerializeField] private TextMeshProUGUI manaTMP;
	[SerializeField] private TextMeshProUGUI expTMP;

	private void Update()
	{
		UpdatePlayerUI();
	}

	private void UpdatePlayerUI()
	{
		float t = 10f * Time.deltaTime;
		healthBar.fillAmount = Mathf.Lerp( healthBar.fillAmount, stats.health / stats.maxHealth, t);
		manaBar.fillAmount = Mathf.Lerp(manaBar.fillAmount, stats.mana / stats.maxMana, t);
		expBar.fillAmount = Mathf.Lerp(expBar.fillAmount, stats.currentExp / stats.nextLevelExp, t);
		
		levelTMP.text = $"Level {stats.level}";
		healthTMP.text = $"{stats.health} / {stats.maxHealth}";
		manaTMP.text = $"{stats.mana} / {stats.maxMana}";
		expTMP.text = $"{stats.currentExp} / {stats.nextLevelExp}";

	}
}
